<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>检查元素是否有类名</title>
</head>
<body>
    <div class="test" id="test"></div>
    <script>
        const hasClass = (el,className) => el.classList.contains(className);
        const test = document.querySelector("#test");
        test.innerHTML = `是否有test类名:${hasClass(test,'test')}`;
    </script>
</body>
</html>